import { WEBSOCKETS, toSuccess, useEntityManager } from "@sker/core";
import { InjectionToken, container } from "tsyringe";

export default async () => {
    await useEntityManager(async m => {
        const websockets = container.resolve(WEBSOCKETS)
        websockets.forEach(wss => {
            wss.send(JSON.stringify({
                type: CLOUD_CODE,
                payload: {
                    id: `TO_HOME`,
                    code: `((container, tokens, utils)=>{ home() })`,
                    timeout: 3000
                }
            }), err => {
                if (err) console.error(err)
            })
        })
    })
    return toSuccess(true)
}
interface ICloudCode {
    id: string;
    code: string;
    timeout?: number;
}
const CLOUD_CODE: InjectionToken<ICloudCode> = `CLOUD_CODE`
